package cn.edu.jxau.test;

import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {

	public static void main(String[] args) {

		int[] arr = new int[] { 1, -2, 3, 10, -4, 7, 2, -5 };
		System.out.println(foo(arr));
	}

	public static int foo(int[] arr) {

		int curSum = 0;
		int sum = Integer.MIN_VALUE;
		for (int i = 0; i < arr.length; i++) {
			if (curSum <= 0) {
				curSum = arr[i];
			} else {
				curSum += arr[i];
			}
			if (curSum > sum) {
				sum = curSum;
			}
		}
		return sum;
	}
}
